package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import util.JDBCUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;
import java.util.Map;

@WebServlet(name = "getPicIDandPicTagZZY", value = "/getPicIDandPicTagZZY")
public class getPicIDandPicTagZZY extends HttpServlet {
    private JdbcTemplate jdbcTemplate =  new JdbcTemplate(JDBCUtils.getDataSource());

    public List getComment()
    {
        String sql="select * from picturetag";
        List<Map<String,Object>> rows=jdbcTemplate.queryForList(sql);
        return rows;
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List list = getComment();
        ObjectMapper mapper = new ObjectMapper();
        response.setContentType("application/json;charset=utf-8");
        mapper.writeValue(response.getWriter(),list);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request,response);
    }
}
